#-*- coding:utf-8 -*-
'''
Created on Nov 29, 2012

@author: bbg
'''

from os import path
import logging
from datetime import datetime

class Log(object):
    
    #default value
    __path__ = '/tmp' 
    __leve__ = logging.DEBUG 
    
    __last_date__ = ''

    def __init__(self):        
        pass
            
    @staticmethod
    def setLevel(level):
        Log.__leve__ = level        
            
    @staticmethod
    def setPath(logPath):
        Log.__path__ = logPath
        if path.exists(Log.__path__) == False:
            raise 'path not exists:%s' % Log.__path__
        
    def e(self, msg):
        curDate = datetime.now().strftime('%Y%m%d')
        if curDate != Log.__last_date__:
            fileName = '%s/aicloud.%s.log' % (Log.__path__, curDate)
        
            logging.basicConfig(filename = fileName, 
                            format = "%(asctime)s %(levelname)s:%(message)s",  
                            datefmt='%Y-%m-%d %H:%M:%S', 
                            level = Log.__leve__)
            Log.__last_date__ = curDate
        
        logging.error(msg)
        
    def d(self, msg):
        curDate = datetime.now().strftime('%Y%m%d')
        if curDate != Log.__last_date__:
            fileName = '%s/sports.%s.log' % (Log.__path__, curDate)
        
            logging.basicConfig(filename = fileName, 
                            format = "%(asctime)s %(levelname)s:%(message)s",  
                            datefmt='%Y-%m-%d %H:%M:%S', 
                            level = Log.__leve__)
            Log.__last_date__ = curDate
        
        logging.debug(msg)

            
            
        
        